/*
 * Copyright 2025 The JA-SIG Collaborative. All rights reserved.
 * distributed with this file and available online at
 */
package com.lap.auth.adapter.driving.persistence.menu;

import com.lap.auth.adapter.driving.persistence.menu.po.MenuPo;
import com.lap.auth.domain.menu.Menu;
import com.lap.auth.domain.menu.valueobject.MenuType;
import com.lap.framework.common.tool.EnumUtil;
import java.util.List;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper(componentModel = "spring")
public interface MenuConverter {

  @InheritInverseConfiguration
  MenuPo toPo(Menu menu);

  @Mapping(target = "event", ignore = true)
  Menu toDomain(MenuPo menuPo);

  List<Menu> toDomains(List<MenuPo> list);

  default MenuType codeToMenuType(Integer code) {
    return EnumUtil.fromCode(MenuType.class, code);
  }

  default Integer menuTypeToCode(MenuType type) {
    return type.getCode();
  }
}
